<!DOCTYPE html>
<html>
<head>
<title>SwiftAdmin安装向导</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> 
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/static/js/layui/css/layui.css">
<link rel="stylesheet" href="/static/css/install.css?{:config('app.version')}">
<script src="/static/js/layui/layui.js"></script>
</head>
<body>

<div class="layui-header">
	<div class="layui-container">
		<h1 class="logo"><a href="https://www.SwiftAdmin.net"><img class="pic" src="__ADMINIMAGES__/logo.png" alt=""><span>SwiftAdmin</span></a></h1>
		<div class="title">安装向导</div>
	</div>
</div>


<div class="layui-content" style="padding-top: 0px;">
	<div class="layui-container">
		<div class="layui-row">

			<div class="layui-step-group">
	            <div class="layui-step layui-active">
	                <div class="layui-sort">1</div>
	                <div class="layui-desc">检查安装环境</div>
	            </div>
	            <div class="layui-step layui-active layui-line"></div>
	            <div class="layui-step layui-active">
	                <div class="layui-sort">2</div>
	                <div class="layui-desc">创建数据库</div>
	            </div>
	            <div class="layui-step layui-active layui-line"></div>
	            <div class="layui-step layui-active ">
	                <div class="layui-sort">3</div>
	                <div class="layui-desc">安装成功</div>
	            </div>
	    	</div>

			<div class="layui-col-md12">
				<div class="layui-card layui-fixed">
					<div class="layui-card-header">
						<span>3 安装成功</span>
						<span class="layui-card-version">{:config('app.version')}</span>
					</div>
					<div class="layui-card-body">
						<div class="layui-install">
							<div class="tips">正在安装，请稍后...</div> 	
							<div class="layui-progress layui-progress-big" lay-showPercent="true">
	  							<div class="layui-progress-bar layui-bg-blue" lay-percent=""></div>
							</div>	

							<div class="layui-install-logs"><li>创建数据表...</li></div>			
						</div>

						<div class="layui-complete" style="display: none">
							<div class="layui-success">SWIFTADMIN安装成功</div>
							<blockquote class="layui-elem-quote layui-text" style="border-left: 0px;text-align: left;margin-bottom: 30px;">
							  1. <a href="/" target="_blank">请不要将后台地址泄露给他人，如有泄露请及时修改</a><br/>
							  2. <a href="/" target="_blank" class="layui-admin">后台地址：</a><br>
							  3. 系统默认管理员账号为:admin
							</blockquote>
							<a href="/" target="_blank" class="layui-btn layui-btn-normal layui-btn-fixed">访问前台</a>
							<a href="/" target="_blank" class="layui-btn layui-btn-normal layui-btn-admin">访问后台</a>
						</div>
		    		</div>
					</div>
				</div>
			</div>
		</div>
    </div>
</div>
<style>.layui-footer{    
		position: revert;
        padding: 0px;
    }</style>
<div class="layui-footer">copyright © 2020 SwiftAdmin all rights reserved.</div>
</body>


<script type="text/javascript">
	layui.use(['jquery','layer','element'],function() {
		var layer = layui.layer;
		var jquery = layui.jquery;
		var element = layui.element;

		// 随机字符串
		function randomString(len) {
		　　len = len || 32;
		　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
		　　var maxPos = $chars.length;
		　　var pwd = '';
		　　for (i = 0; i < len; i++) {
		　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
		　　}
		　　return pwd;
		}

		// 加载数据信息
		jquery.get('/install.php/index/install',{},function(res){
			if (res.code == 200) {
				queryProgress();
			} else {
			    layer.msg(res.msg,'error');
			}
		});

		var progress = 1;
        var queryProgress = function() {
			
			jquery.ajax({
				url: '/install.php/index/progress',
				data: {
					key: progress
				},
				type: 'get',
				async: false,
				dataType: 'json',
				success:function(res) {
				
					// 设置延时
					if (!res || typeof res.msg == undefined) {
						setTimeout(queryProgress, 1000);
						return false;
					}
					
					// 查找元素
					var html = '';
					var logsElem = jquery('.layui-install-logs');
					if (res.code == 200) {
						if (res.msg) {
							html += '<li class="'+ res.key +'">'+res.msg+'</li>';
						}
						if (progress < res.total) {
							progress += 1;
						}
					} else if (res.code == 101) { // 错误信息
						html = '<li><font color="red">'+res.msg+'</font></li>';
					}

					if (parseInt(res.progress) >= 100) {
						jquery('.layui-install').remove();
						var admin = jquery('.layui-admin'), loginfile=randomString(8)+'.php';
						admin.attr('href','/'+loginfile);
						admin.html('后台地址：https://'+ location.host +'/'+loginfile);
						jquery('.layui-btn-admin').attr('href','/'+loginfile);
						jquery('.layui-complete').show();
						jquery.get('/install.php/index/clear?loginfile='+loginfile,{},function(res){});
						layer.msg(res.msg);
					}
					else {
						// 移动焦点
						logsElem.append(html);
						if (logsElem[0].scrollHeight >= logsElem[0].clientHeight) {
							var scrollTop = logsElem[0].scrollHeight-logsElem[0].clientHeight;
							logsElem.scrollTop(scrollTop);
						}
						setTimeout(queryProgress, 10);
					}
					jquery('.layui-progress-bar').attr('lay-percent',res.progress) && element.render();
				}
			});
        }
	})
</script>
</html>